package com.example.administrator.animationdemo;

import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

    ImageView ivFrameAnim;
    Drawable [] drawables;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ivFrameAnim = findViewById(R.id.iv_frame_anim);
//        Glide.with(this).asGif().load(R.drawable.timg).into(ivFrameAnim);
        drawables = new Drawable[]{
                getResources().getDrawable(R.drawable.timg_01),
                getResources().getDrawable(R.drawable.timg_02),
                getResources().getDrawable(R.drawable.timg_03),
                getResources().getDrawable(R.drawable.timg_04),
                getResources().getDrawable(R.drawable.timg_05),
                getResources().getDrawable(R.drawable.timg_06),
                getResources().getDrawable(R.drawable.timg_07),
                getResources().getDrawable(R.drawable.timg_08),
                getResources().getDrawable(R.drawable.timg_09),

        };
      handler.postDelayed(runnable,1000);

    }

    int count=0;
    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if(count>drawables.length-2){
                count=0;
            }
            Drawable drawableArray[] = {drawables[count],drawables[count+1]};
            TransitionDrawable td_fade = new TransitionDrawable(drawableArray);
            ivFrameAnim.setImageDrawable(td_fade);
            td_fade.startTransition(1000);
            handler.postDelayed(this,1000);
            count+=2;
        }
    };

}
